var express = require("express")
var router = express.Router()

const { organModel, roleModel, doctorModel } = require("../db/organ_model")
const multiparty = require("multiparty")

/* 
机构管理查询
*/
router.get("/organ", async (req, res) => {
    let data = await organModel.find().populate("doctor_team")
    res.send({
        data,
        mes: "查找成功"
    })
})

/* 
角色管理查询
*/
router.get("/role",async(req,res)=>{
    let data = await roleModel.find()
    res.send({
        data,
        mes:"角色查询成功"
    })
})


/* 
医生管理查询
*/
router.get("/doctor",async(req,res)=>{
    let data = await doctorModel.find().populate("organ").populate("doctor_team").populate("role")
    res.send({
        data,
        mes:"医生查询成功"
    })
})



router.post("/uploadImg", async (req, res) => {
    let form = new multiparty.Form()
    form.parse(req, (err, formDate, imgData) => {
        console.log(imgData, '11111111');
        res.send({
            path: "http://localhost:3461/" + imgData.file[0].path
        })
    })
})


module.exports = router;